package com.easyexcel;

import com.alibaba.excel.EasyExcel;
import com.alibaba.excel.ExcelWriter;
import com.alibaba.excel.write.builder.ExcelWriterSheetBuilder;
import com.alibaba.excel.write.metadata.WriteSheet;
import com.alibaba.excel.write.style.column.LongestMatchColumnWidthStyleStrategy;
import com.alibaba.fastjson.JSONArray;
import org.apache.commons.lang3.ArrayUtils;

import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.*;

public class Test {

    private static final String enter = "\n";

    public static String[] a = {"a","b","c"};

    public static void main(String[] args) {
        //System.err.println(ArrayUtils.contains(a,null));.
        Test test = new Test();

        //test.run();

        test.run2();




    }

    public void run(){
        List<List<String>> heads = new ArrayList<List<String>>();
        List<String> head = new ArrayList<String>();
        head.add("地区名称");
        heads.add(head);

        head = new ArrayList<String>();
        head.add("总户数");
        heads.add(head);

        List<List<Object>> datas = new ArrayList<>();
        List<Object> datas1 = new LinkedList<>();
        datas1.add("李召");
        datas1.add(1);
        datas.add(datas1);

        List<Object> datas2 = new LinkedList<>();
        datas2.add("金城");
        datas2.add(2);
        datas.add(datas2);

        List<DemoExcel> a = new LinkedList<>();
        a.add(new DemoExcel("李召哈",1));
        a.add(new DemoExcel("金城哈",2));


        try {
            //.
            //                    registerConverter(new ConverterHandler())
            EasyExcel.write("C:/Users/domains90/Desktop/a.xlsx").
                    registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).registerWriteHandler(new CommentWriteHandler()).head(heads).sheet().doWrite(datas);
//            excelWriter = EasyExcel.write("C:/Users/domains90/Desktop/a.xlsx").
//
//                    registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).build();
//
//            WriteSheet writeSheet = EasyExcel.writerSheet(0, "模板").head(DemoExcel.class).registerConverter(new ConverterHandler()).build();
//            excelWriter.write(datas, writeSheet);
        } finally {

        }

    }

    public void run2(){
        List<DemoExcel> a = new LinkedList<>();
        a.add(new DemoExcel("李召哈",1));
        a.add(new DemoExcel("金城哈",2));
        EasyExcel.write("C:/Users/domains90/Desktop/a.xlsx").head(DemoExcel.class).
                registerWriteHandler(new LongestMatchColumnWidthStyleStrategy()).sheet().registerWriteHandler(new CommentWriteHandler()).doWrite(a);
    }


}
